package com.xyazm.order.factory;

import com.xyazm.common.enums.OrderOperateTypeEnum;
import com.xyazm.common.enums.OrderStatusChangeEnum;
import com.xyazm.order.dao.OrderOperateLogDAO;
import com.xyazm.order.domain.entity.OrderInfoDO;
import com.xyazm.order.domain.entity.OrderOperateLogDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单操作日志工厂
 * @Author: xuyou
 * @Date: 2022/6/23 17:47
 */
@Slf4j
@Component
public class OrderOperateLogFactory {

    @Autowired
    private OrderOperateLogDAO operateLogDAO;

    /**
     * 构建订单操作日志
     * @param statusChange 订单状态变更
     * @return 订单操作内容
     */
    public OrderOperateLogDO buildOrderOperateLog(OrderInfoDO orderInfoDO, OrderStatusChangeEnum statusChange){
        OrderOperateTypeEnum operateType = statusChange.getOperateType();
        Integer preStatus = statusChange.getFromStatus().getCode();
        Integer currentStatus = statusChange.getToStatus().getCode();
        return buildOrderOperateLog(orderInfoDO, operateType, preStatus,currentStatus,operateType.getMsg());
    }
    /**
     * 构建订单操作日志
     * @author xuyou
     * @date: 2022/6/23 17:49
     * @param: orderInfo 订单信息
     * @param: operateType 操作类型
     * @param: preStatus 前置状态
     * @param: currentStatus 当前状态
     * @param: operateRemark 备注
     */
    private OrderOperateLogDO buildOrderOperateLog(OrderInfoDO orderInfoDO, OrderOperateTypeEnum operateType,
                                                   int preStatus, int currentStatus, String operateRemark) {
        OrderOperateLogDO log = new OrderOperateLogDO();
        log.setOrderId(orderInfoDO.getOrderId());
        log.setOperateType(operateType.getCode());
        log.setPreStatus(preStatus);
        log.setCurrentStatus(currentStatus);
        log.setRemark(operateRemark);
        return log;
    }
}
